/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tecsup.adm.dao;

import com.tecsup.dao.BaseDAO;
import com.tecsup.excepcion.DAOExcepcion;
import com.tecsup.adm.modelo.Departamento;
import com.tecsup.util.ConexionBD;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author Leonel
 */
public class DepartamentoDAO extends BaseDAO{
    
    public Departamento obtenerPorId(int idDepa) throws DAOExcepcion{
        
        String query="SELECT * FROM departamento WHERE idDepartamento=?";
        Departamento vo = new Departamento();
        Connection con = null;
        PreparedStatement stmt = null;
        ResultSet rs = null;
        try {
            con = ConexionBD.obtenerConexion();
            stmt = con.prepareStatement(query);
            stmt.setInt(1, idDepa);
            rs = stmt.executeQuery();
            if (rs.next()) {
                
                vo.setNombDepartamento(rs.getString("nombDepartamento"));
                vo.setDescDepartamento(rs.getString("descDepartamento"));
                vo.setModulo(rs.getString("modulo"));
                
            }
            
        } catch (SQLException e) {
            System.err.println(e.getMessage());
            throw new DAOExcepcion(e.getMessage());
        } finally {
            this.cerrarResultSet(rs);
            this.cerrarStatement(stmt);
            this.cerrarConexion(con);
        }
        return vo;
        
        
    }

}
